package classDAO;

import java.util.List;

import mappedClass.WinaproachRecord;

import org.hibernate.Query;
import org.hibernate.Session;

import testhibernate.HibernateUtil;

public class WinaproachDAO implements DAO{

	public List findAll() {
		Session s = HibernateUtil.getSessionFactory().openSession();
		List list = s.createQuery("from WinaproachRecord t").list();
		s.close();
		return list;
	}

	public Object getById(int id) {
		Session s = HibernateUtil.getSessionFactory().openSession();

		return (WinaproachRecord) s.get(WinaproachRecord.class, id);
	}

	public int getIdByName(String name) {
		Session s = HibernateUtil.getSessionFactory().openSession();

		Query q = s
				.createQuery(
						"SELECT id FROM WinaproachRecord WHERE name= :name")
				.setString("name", name);

		int id = (Integer) q.uniqueResult();
		return id;
	}

}
